ci: Add a codestyle.sh
authorColin Walters <walters@verbum.org>
Tue, 31 May 2022 14:57:00 +0000 (10:57 -0400)
committerColin Walters <walters@verbum.org>
Tue, 31 May 2022 15:42:42 +0000 (11:42 -0400)
This matches what we do in rpm-ostree.  Move the `glnx_fd_close`
bits out of `make syntax-check` in preparation for dropping that.

.cci.jenkinsfile
cfg.mk
ci/codestyle.sh [new file with mode: 0755]
ci/gh-build.sh

index ff9412494c386edcb8f50ae3cfe42292afb0e97d..af9faed5dff4e40ad126df923e0ee33016db42ac 100644 (file)
@@ -4,6 +4,9 @@ stage("Build") {
   def n = 5
   buildPod(memory: "2Gi", cpu: "${n}") {
       checkout scm
+      stage("Static analysis") {
+          shwrap("./ci/codestyle.sh")
+      }
       stage("Core build") {
         shwrap("""
           # fetch tags so `git describe` gives a nice NEVRA when building the RPM
diff --git a/cfg.mk b/cfg.mk
index 471ccbc9187999a77bf40fbb3659bb1a65374914..51e1833d264289ba47b0bcca217cbee5cc651294 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -31,10 +31,6 @@ sc_glnx_errno_prefix_colon:
        @prohibit='\<glnx_throw_errno_prefix *\(.*: ",' halt="don't add trailing : for glnx_throw_errno_prefix" \
          $(_sc_search_regexp)
 
-sc_glnx_no_fd_close:
-       @prohibit='\<glnx_fd_close int' halt="Use glnx_autofd, not glnx_fd_close"       \
-         $(_sc_search_regexp)
-
 #SHELL=bash -x
 show-vc-list-except:
        @$(VC_LIST_EXCEPT)
diff --git a/ci/codestyle.sh b/ci/codestyle.sh
new file mode 100755 (executable)
index 0000000..1cf0a23
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+# Tests that validate structure of the source code;
+# can be run without building it.
+set -euo pipefail
+
+# Don't hard require Rust
+if command -v cargo >/dev/null; then
+echo -n "checking rustfmt... "
+for crate in $(find -iname Cargo.toml); do
+    if ! cargo fmt --manifest-path ${crate} -- --check; then
+        echo "cargo fmt failed; run: cd $(dirname ${crate}) && cargo fmt" 1>&2
+        exit 1
+    fi
+done
+echo "ok"
+fi
+
+echo -n 'grep-based static analysis... '
+patterns=(glnx_fd_close)
+for pat in "${patterns[@]}"; do
+    if git grep "${pat}" | grep -v codestyle\.sh; then
+        echo "Files matched prohibited pattern: ${pat}" 1>&2
+        exit 1
+    fi
+done
+echo ok
index fdc795692986c8dd09b4182e10851660be1ba220..48c16cda770e100f65958d6c0584ce7bbd54c360 100755 (executable)
@@ -26,6 +26,9 @@
 set -euo pipefail
 set -x
 
+# First, basic static analysis
+./ci/codestyle.sh
+
 NOCONFIGURE=1 ./autogen.sh
 
 srcdir="$(pwd)"